package com.jiuxian.scheduling.commons;

import com.jiuxian.scheduling.util.DubboUtil;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by wangjingqing on 2017/12/18.
 */
public class DubboApplicationContext {

    /** 放对象map */
    static Map<String,Object> objectMap = new ConcurrentHashMap<>();


    public static Object getObject(String name,String zkPath,String version,String group){
        try {
            Object obj = objectMap.get(name);
            if(obj != null){
                return obj;
            }
            synchronized (name){
                obj = objectMap.get(name);
                if(obj != null){
                    return obj;
                }
                obj = DubboUtil.getRpcObject(Class.forName(name),zkPath,version,group);
                objectMap.put(name,obj);
                return obj;
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
